package com.usefullc.english.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.english.domain.Note;
import com.usefullc.english.mapper.NoteMapper;
import com.usefullc.english.query.NoteQuery;
import com.usefullc.english.vo.NoteVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 笔记服务类
 * @author: 星空
 * @date: 2022-08-11
 */
@Service
public class NoteService extends AbstractBizService<NoteMapper, Note, NoteQuery> {


    @Override
    protected QueryWrapper<Note> getQueryWrapper(NoteQuery query) {
        QueryWrapper<Note> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<NoteVo> findVoByPage(NoteQuery query){
        Pager<Note> page = this.findByPage(query);
        Pager<NoteVo> newPage = new Pager<>(page);
        List<Note> dataList = page.getDataList();
        List<NoteVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (Note note : dataList) {
            NoteVo noteVo = BeanUtils.beanCopy(note, NoteVo.class);
            newDataList.add(noteVo);
        }
        return newPage;
    }


}
